<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>类和实例 继承</title>
</head>
<body>
    

    <script>
        
        {
            // 类和实例
            class Parent {
                constructor (name='mm') {
                    this.name = name;
                }
            }

            let instance_parent = new Parent('vv');
            
            console.log(instance_parent);
            
        }    
        
        {
            // 继承

            class Parent {
                constructor (name='mm') {
                    this.name = name;
                }

                
            }

            class Child extends Parent {

            }

            console.log('extends',new Child());

        }
        

        {
            // 继承 覆盖参数
            class Parent {
                constructor (name='mm') {
                    this.name = name;
                }
            }

            class Child extends Parent {
                constructor (name='child') {
                    super(name); // super () 覆盖父级的参数列表
                    this.type = 'child function';
                }
            }
            console.log('extends-参数',new Child('child change'));
        }


        {

            // getter setter  

            class Parent {
                constructor (name='mm') {
                    this.name = name;
                }

                get longName () {
                return 'abcdefg' + this.name; 
                }

                set longName (value) {
                    this.name = value;
                }

            }

            let c = new Parent();

            console.log('getter',c.longName);

            c.longName = 'hello';

            console.log('setter',c.longName);

        }

        {
            // 关键词 static 静态方法 -> 通过 类 去调用 而【不是】通过 实例调用
            class Parent {
                constructor (name='mm') {
                    this.name = name;
                }

                static tell () {
                    console.log('tell');
                }

            }

            Parent.tell();

        }

        {
            // 静态属性 直接在类上定义

            class Parent {
                constructor (name='mm') {
                    this.name = name;
                }

                static tell () {
                    console.log('tell');
                }
            }

            Parent.type = 'test';

            console.log('静态属性',Parent.type);

        }

    </script>
</body>
</html>